#include "wuNuvolManager.h"

wuNuvolManager::wuNuvolManager()
{

}

wuNuvolManager::~wuNuvolManager()
{
}

bool wuNuvolManager::capture(ofImage *currImg, ofImage *bgImg, int x_offset)
{
	bool bCambiazo = true;

	wuBaseManager::capture(currImg, bgImg, x_offset);

	return bCambiazo;
}

void wuNuvolManager::addBitxo(ofImage *_skin, ofRectangle rect, vector <ofPoint> * _pts )
{
	wuNuvol nuvol;
	nuvol.setup(box2d, _skin, rect);
	nuvols.push_back(nuvol);
}

void wuNuvolManager::draw(bool bDrawlines, int offX)
{
        for (int i = 0; i < nuvols.size(); i++)
            nuvols[i].draw(bDrawlines, offX);

}


void wuNuvolManager::drawSelected(bool bDrawlines, int offX)
{
    if(selection.width < vw || selection.height < vh)
    {

        for (int i = nuvols.size()-1; i >= 0; i--)
        {
            bool condi = (nuvols[i].getPosition().y > selection.y) && (nuvols[i].getPosition().y < selection.y + selection.height) &&
             (nuvols[i].getPosition().x > selection.x + x_scroll) && (nuvols[i].getPosition().x < selection.x + x_scroll + selection.width);

            if (condi)
                nuvols[i].draw(bDrawlines, offX);
        }
    }else
    {
        for (int i = 0; i < nuvols.size(); i++)
            nuvols[i].draw(bDrawlines, offX);
    }
}

void wuNuvolManager::update()
{
        for (int i = 0; i < nuvols.size(); i++)
            nuvols[i].update();
}

void wuNuvolManager::startRain()
{
    for (int i = 0; i < nuvols.size(); i++)
		nuvols[i].startRain();
}
void wuNuvolManager::stopRain()
{
    for (int i = 0; i < nuvols.size(); i++)
		nuvols[i].stopRain();
}
void wuNuvolManager::clear()
{
    if(selection.width < vw || selection.height < vh)
    {

        for (int i = nuvols.size()-1; i >= 0; i--)
        {
            bool condi = (nuvols[i].getPosition().y > selection.y) && (nuvols[i].getPosition().y < selection.y + selection.height) &&
             (nuvols[i].getPosition().x > selection.x + x_scroll) && (nuvols[i].getPosition().x < selection.x + x_scroll + selection.width);

            if (condi)
            {
                nuvols[i].stopRain();
                nuvols[i].clear();
                nuvols.erase(nuvols.begin()+i);
            }
        }
    }else
    {
        for (int i = 0; i < nuvols.size(); i++)
            nuvols[i].stopRain();
        for (int i = 0; i < nuvols.size(); i++)
            nuvols[i].clear();
        nuvols.clear();
    }

}

void wuNuvolManager::touch(int _x,int _y, int forceX, int forceY)
{
    for (int i = 0; i < nuvols.size(); i++)
		nuvols[i].touch(_x, _y, forceX, forceY);
}

bool wuNuvolManager::drag(int _x,int _y)
{
    bool bDrag=false;

    for (int i = 0; i < nuvols.size(); i++)
		if(nuvols[i].drag(_x + x_scroll, _y))
            bDrag=true;

    return bDrag;

}
void wuNuvolManager::rain(bool _bRain)
{
    if(_bRain)
        startRain();
    else
        stopRain();
}
